﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {

    public class TestTextureCombiner {
        [Fact]
        public void TestConstructor () {
            var cmb = new TextureCombiner ();

            Assert.Equal (TextureCombiner.Modulate, cmb.ColorFunction);
            Assert.Equal (TextureCombiner.Texture, cmb.ColorSource[0]);
            Assert.Equal (TextureCombiner.Previous, cmb.ColorSource[1]);
            Assert.Equal (TextureCombiner.Constant | TextureCombiner.Alpha, cmb.ColorSource[2]);
            Assert.Equal (TextureCombiner.Modulate, cmb.AlphaFunction);
            Assert.Equal (TextureCombiner.Texture, cmb.AlphaSource[0]);
            Assert.Equal (TextureCombiner.Previous, cmb.AlphaSource[1]);
            Assert.Equal (TextureCombiner.Constant, cmb.AlphaSource[2]);
            Assert.Equal (0x01010101, cmb.Scaling);
        }

        [Fact]
        public void TestFunctions () {
            var cmb = new TextureCombiner ();
            cmb.SetFunctions (TextureCombiner.Add, TextureCombiner.Subtract);

            Assert.Equal (TextureCombiner.Add, cmb.ColorFunction);
            Assert.Equal (TextureCombiner.Subtract, cmb.AlphaFunction);
        }

        [Fact]
        public void TestSetColorSource () {
            var cmb = new TextureCombiner ();
            cmb.SetColorSource (0, TextureCombiner.Constant);
            cmb.SetColorSource (1, TextureCombiner.Primary);
            cmb.SetColorSource (2, TextureCombiner.Previous);

            Assert.Equal (TextureCombiner.Constant, cmb.ColorSource[0]);
            Assert.Equal (TextureCombiner.Primary, cmb.ColorSource[1]);
            Assert.Equal (TextureCombiner.Previous, cmb.ColorSource[2]);
        }

        [Fact]
        public void TestSetAlphaSource () {
            var cmb = new TextureCombiner ();
            cmb.SetAlphaSource (0, TextureCombiner.Constant);
            cmb.SetAlphaSource (1, TextureCombiner.Primary);
            cmb.SetAlphaSource (2, TextureCombiner.Previous);

            Assert.Equal (TextureCombiner.Constant, cmb.AlphaSource[0]);
            Assert.Equal (TextureCombiner.Primary, cmb.AlphaSource[1]);
            Assert.Equal (TextureCombiner.Previous, cmb.AlphaSource[2]);
        }


        [Fact]
        public void TestScaling () {
            var cmb = new TextureCombiner ();
            cmb.SetScaling (0x010204, 0x04);

            Assert.Equal (0x04010204, cmb.Scaling);
        }

        [Fact]
        public void TestDuplicate () {
            var cmb = new TextureCombiner ();
            cmb.SetFunctions (TextureCombiner.Add, TextureCombiner.Subtract);
            cmb.SetColorSource (0, TextureCombiner.Constant);
            cmb.SetColorSource (1, TextureCombiner.Primary);
            cmb.SetColorSource (2, TextureCombiner.Previous);
            cmb.SetAlphaSource (0, TextureCombiner.Constant);
            cmb.SetAlphaSource (1, TextureCombiner.Primary);
            cmb.SetAlphaSource (2, TextureCombiner.Previous);
            cmb.SetScaling (0x010204, 0x04);
            cmb.UserID = 100;

            var dup = (TextureCombiner)cmb.Duplicate ();

            Assert.Equal (cmb.ColorFunction, dup.ColorFunction);
            Assert.Equal (cmb.ColorSource[0], dup.ColorSource[0]);
            Assert.Equal (cmb.ColorSource[1], dup.ColorSource[1]);
            Assert.Equal (cmb.ColorSource[2], dup.ColorSource[2]);
            Assert.Equal (cmb.AlphaFunction, dup.AlphaFunction);
            Assert.Equal (cmb.AlphaSource[0], dup.AlphaSource[0]);
            Assert.Equal (cmb.AlphaSource[1], dup.AlphaSource[1]);
            Assert.Equal (cmb.AlphaSource[2], dup.AlphaSource[2]);
            Assert.Equal (cmb.Scaling, dup.Scaling);
            Assert.Equal (cmb.UserID, dup.UserID);
        }
    }
}
